package com.example.demo.core.web.core.model;

import lombok.Data;
import org.dromara.hutool.core.text.StrUtil;

/**
 * @author airhead
 */
@Data
public class SortReq {
  private String sortMethod;
  private String sortField;

  /**
   * 构建排序
   *
   * <p>1无特殊要求，直接调用
   *
   * <p>2.初始化字段，后调用
   */
  public void buildSort() {
    if (StrUtil.isNotBlank(getSortField()) && StrUtil.isNotBlank(getSortMethod())) {
      if ("asc".equalsIgnoreCase(getSortMethod())) {
        setSortMethod("asc");
      } else {
        setSortMethod("desc");
      }

      String sortField = StrUtil.toUnderlineCase(getSortField());
      setSortField(sortField);
    } else {
      setSortMethod("");
      setSortField("");
    }
  }
}
